#include once "fbgfx.bi"
#include once "ext/graphics/image.bi"

type not_callback
    func as sub(byval as any ptr)
    _data as any ptr
    declare constructor( byval x as sub(byval as any ptr), byval d as any ptr )
end type

type notification
    declare constructor(byref l1 as string,byref l1 as string,byref l1 as string,byval length as double, byval ico as ext.gfx.image ptr = 0, byval c as not_callback ptr = 0)
    as string line1, line2, line3
    as double start, length
    as ext.gfx.image ptr icon
    declare destructor()
    as not_callback ptr cb
end type

type notification_list
    as notification ptr _data
    as notification_list ptr _next
    declare destructor()
    declare constructor()
    declare constructor( byval note as notification ptr )
    declare sub push( byval note as notification ptr )
    declare function pop( ) as notification ptr
end type

constructor.not_callback(byval x as sub(byval as any ptr), byval d as any ptr )
    func = x
    _data = d
end constructor

sub notification_list.push(  byval note as notification ptr )

    if _data = 0 andalso _next = 0 then
        _data = note
        return
    end if

    var newitem = new notification_list(note)
    var list = @this

    while list->_next <> 0
        list = list->_next
    wend

    list->_next = newitem

end sub

function notification_list.pop() as notification ptr

    if _data = 0 then return 0

    var ret = _data

    if _next = 0 then
        _data = 0
        return ret
    end if

    var temp = _next
    _data = temp->_data
    _next = temp->_next

    return ret

end function

constructor notification_list()
end constructor

constructor notification(byref l1 as string,byref l2 as string,byref l3 as string,byval length as double, byval ico as ext.gfx.image ptr = 0, byval c as not_callback ptr = 0)

    line1 = l1
    line2 = l2
    line3 = l3
    this.length = length
    icon = ico
    cb = c

end constructor

destructor notification()
    if icon <> 0 then
        delete icon
    end if
    if cb <> 0 then
        cb->func(cb->_data)
        delete cb
    end if
end destructor

constructor notification_list( byval note as notification ptr )
    _data = note
    _next = 0
end constructor

destructor notification_list()

    if _data <> 0 then delete _data
    if _next <> 0 then delete _next

end destructor

